//
//  NYCourseIntroduceCell.m
//  NiuWaJiaoYu
//
//  Created by MinLison on 2018/1/10.
//  Copyright © 2018年 niuwaketang. All rights reserved.
//

#import "NYCourseIntroduceCell.h"


@interface NYCourseIntroduceCell ()

@property (nonatomic, strong) UILabel *titleLabel;
@property (nonatomic, strong) UILabel *introduceLabel;
@property (nonatomic, strong) TTTAttributedLabel *learnLabel;

@end

@implementation NYCourseIntroduceCell

//MARK :Nimbus
- (BOOL)shouldUpdateCellWithObject:(NYCourseModel *)object {
    
    if (![object isKindOfClass:[NYCourseModel class]]) {
        return false;
    }
    [self updateContentWithModel:object];
    return true;
}
//+ (CGFloat)heightForObject:(id)object identifier:(NSString *)identifier atIndexPath:(NSIndexPath *)indexPath tableView:(UITableView *)tableView {
//
//    return 50.f;
//}
- (void)setupView {
    [super setupView];
    //布局
    self.accessoryType = UITableViewCellAccessoryNone;
    
    [self.contentView addSubview:self.titleLabel];
    [self.contentView addSubview:self.introduceLabel];
    [self.contentView addSubview:self.learnLabel];

    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self.contentView).offset(24);
        make.height.mas_equalTo(20);
        make.left.equalTo(self.contentView).offset(15);
        make.right.equalTo(self.contentView).offset(-15);
    }];
    [self.introduceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self.titleLabel.mas_bottom).offset(20);
        make.left.equalTo(self.contentView).offset(15);
        make.right.equalTo(self.contentView).offset(-15);
        make.bottom.equalTo(self.contentView.mas_bottom).offset(-90);
    }];
    [self.learnLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self.introduceLabel.mas_bottom).offset(24);
        make.left.equalTo(self.contentView).offset(33);
        make.right.equalTo(self.contentView).offset(-33);
        make.height.mas_equalTo(40);
    }];

}
- (void)updateContent {
    [super updateContent];
}

#pragma mark - Private Method
- (void)updateContentWithModel:(NYCourseModel *)model {
    
    self.titleLabel.text = model.title;
    self.introduceLabel.text = model.introduce;
    
    
    NSString *msgString = [NSString stringWithFormat:@"累计%ld位同学参加了学习，课程总共%ld节",model.study_num,model.course_num];
    
    NSMutableAttributedString *hintString=[[NSMutableAttributedString alloc] initWithString:msgString];
    
    NSRange range0 = [[hintString string]rangeOfString:@"累计"];
    NSRange range1 = [[hintString string]rangeOfString:[NSString stringWithFormat:@"%ld",model.study_num]];
    NSRange range2 = [[hintString string]rangeOfString:@"位同学参加了学习，课程总共"];
    NSRange range3 =[[hintString string]rangeOfString:[NSString stringWithFormat:@"%ld",model.course_num]];
    NSRange range4 = [[hintString string]rangeOfString:@"节"];
    
    [hintString addAttribute:NSForegroundColorAttributeName value:UIColorMakeWithHex(@"#999999") range:range0];
    [hintString addAttribute:NSForegroundColorAttributeName value:UIColorMakeWithHex(@"#FF6F40") range:range1];
    [hintString addAttribute:NSForegroundColorAttributeName value:UIColorMakeWithHex(@"#999999") range:range2];
    [hintString addAttribute:NSForegroundColorAttributeName value:UIColorMakeWithHex(@"#FF6F40") range:range3];
    [hintString addAttribute:NSForegroundColorAttributeName value:UIColorMakeWithHex(@"#999999") range:range4];
    
    [_learnLabel setText:hintString];
}

#pragma mark - Setter Getter Methods
- (UILabel *)titleLabel {
    if (!_titleLabel) {
        _titleLabel = [[UILabel alloc] initWithFrame:CGRectZero];
        _titleLabel.font = UIFontBoldMake(18.f);
        _titleLabel.textAlignment = NSTextAlignmentCenter;
        _titleLabel.textColor = UIColorMakeWithHex(@"#333333");
    }
    return _titleLabel;
}
- (UILabel *)introduceLabel {
    if (!_introduceLabel) {
        _introduceLabel = [[UILabel alloc] initWithFrame:CGRectZero];
        _introduceLabel.font = UIFontMake(13.f);
        _introduceLabel.textColor = UIColorMakeWithHex(@"#666666");
        _introduceLabel.numberOfLines = 0;
    }
    return _introduceLabel;
}
- (TTTAttributedLabel *)learnLabel {
    if (!_learnLabel) {
        _learnLabel = [[TTTAttributedLabel alloc] initWithFrame:CGRectZero];
        _learnLabel.font = UIFontMake(14.f);
        _learnLabel.textColor = UIColorMakeWithHex(@"#333333");
        _learnLabel.layer.cornerRadius = 20.f;
        _learnLabel.layer.masksToBounds = true;
        _learnLabel.backgroundColor = UIColorMakeWithHex(@"#F3F4F5");
        _learnLabel.textAlignment = NSTextAlignmentCenter;
    }
    return _learnLabel;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

}

@end
